import React, { Component } from 'react';
import { connect } from 'dva';
import styles from './OrgInfo.less';

@connect(({ org }) => ({
  orgType: org.orgType,
}))
class OrgInfo extends Component {
  constructor(props) {
    super(props);
  }

  getOrgDetail = (orgInfo = {}) => {
    const orgDetail = Object.create(null);
    let type = this.props.orgType.find(type => type.code === orgInfo.structType);
    orgDetail['全称'] = orgInfo.name || '';
    orgDetail['简称'] = orgInfo.shortName || '';
    orgDetail['编码'] = orgInfo.code || '';
    orgDetail['类型'] = (type && type.name) || '';
    orgDetail['描述'] = orgInfo.description || '';
    return orgDetail;
  };

  render() {
    const { data } = this.props;
    let orgDetail = this.getOrgDetail(data);
    return (
      <div className={styles.orgInfo}>
        <div className={styles.title}>组织详情</div>
        <ul className={styles.wrapper}>
          {Object.keys(orgDetail).map((key, index) => {
            return (
              <li className={styles.list} key={index}>
                <span className={styles.label}>{key}</span>
                <span className={styles.content}>{orgDetail[key]}</span>
              </li>
            );
          })}
        </ul>
      </div>
    );
  }
}

export default OrgInfo;
